< previous page page_283 next page >

Page 283
2. Next, add a module-level variable called mboolLoadError to the (General) (Declarations) area of this form.
3. Type in the DCErrorCheck() procedure, as shown here:
Private Sub DCErrorCheck(ByVal ErrorNumber As Long, _
Description As String, _
fCancelDisplay As Boolean)
If Not mboolLoadError Then
MsgBox Description
mboolLoadError = True
fCancelDisplay = True
Else
fCancelDisplay = True
End If
End Sub
analysis.gifI wrote the Error event of the data control to call a procedure I wrote called DCErrorCheck(). In the DCErrorCheck() procedure, I check another module-level variable called mboolLoadError to determine whether an error has already occurred on another data control. If it has, I simply cancel the display of the error from this data controls Error event. This way, if I have three data controls and each one is trying to call a database thats not there, I dont get three error messages that are all the same.

EXERCISE
Test the Error Handling
1. Close down the Visual Basic design environment so that the data controls on the forms will release the Access MDB.
2. Rename the Employees.mdb file to another name.
3. Reload the sample project and run the example to see the error message appear.
4. You could also try opening the database for exclusive use in Access and run the example to see a different error message.
5. Dont forget to rename the database back to Employees.mdb.
analysis.gifYou should always test your error handling using different scenarios. For example, what would happen if there were no records in the table?

 
< previous page page_283 next page >

If you like this book, buy it!